﻿using UnityEditor;
using UnityEngine;
using UnityEngine.UIElements;

namespace Ease.EaseNode.Editor.NodeView
{
    public abstract class BaseEaseEditorWindow<T1, T2> : BaseEaseEditorWindow where T1 : BaseEaseChartView where T2 : VisualElement, IUpdateSelection
    {
        protected abstract string VisualTree { get; }
        protected abstract string StyleSheet { get; }

        public virtual void CreateGUI()
        {
            if (DataManager == null)
            {
                Debug.LogError("数据为空");
            }

            // Each editor window contains a root VisualElement object
            VisualElement root = rootVisualElement;

            // Import UXML
            var visualTree = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(VisualTree);
            visualTree.CloneTree(root);

            // A stylesheet can be added to a VisualElement.
            // The style will be applied to the VisualElement and all of its children.
            var styleSheet = AssetDatabase.LoadAssetAtPath<StyleSheet>(StyleSheet);
            root.styleSheets.Add(styleSheet);

            //ChartView
            EaseChartView = root.Q<T1>();
            InitChartView();

            UpdateSelection = root.Q<T2>();

            OnCreateGUIOther();

            //开始绘制。
            EaseChartView.Reset();
        }

        protected abstract void OnCreateGUIOther();
    }
}